class Request{
  constructor(msg){
    this.msg = msg;
  }
}

class Response{
  constructor(msg){
    this.msg = msg;
  }
}

class Filter{
  constructor(req,res) {
    // this.req = req;
    // this.res = res;
  }
  doFilter(req,res,fc){

  }
}

class HTMLFilter extends Filter{
  doFilter(req,res,fc){
    req.msg = req.msg.replace(/\</g,'&lt;');
    //do something
    fc.doFilter(req,res,fc);
    res.msg += '----htmlres----';
    // return false;
  }
}

class SensitiveFilter extends Filter{
  doFilter(req,res,fc){
    req.msg = req.msg.replace(/tqd/g,'***');
    //do sth
    fc.doFilter(req,res,fc);
    res.msg += '----sensitiveres----';
  }

}


class FilterChain{
  constructor(){
    this.chains = [];
    this.index = 0;
  }
  addFilter(filter){
    this.chains.push(filter);
    return this;
  }
  doFilter(req,res,fc){
    if(this.index === this.chains.length) return;
    this.chains[this.index++].doFilter(req,res,fc);
  }
}




var req = new Request('sdf<dd>dffdstq324tqdhttp://www.baidu.com1234data:sgv+html');
var res = new Response('response');
var f1 = new HTMLFilter();
var f2 = new SensitiveFilter();
var fc = new FilterChain();
fc.addFilter(f1).addFilter(f2);
fc.doFilter(req,res,fc);

console.log(req.msg,'+++',res.msg);

